<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="__STATIC__/template/favicon.ico" >
    <link rel="Shortcut Icon" href="__STATIC__/template/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="__STATIC__/template/lib/html5shiv.js"></script>
    <script type="text/javascript" src="__STATIC__/template/lib/respond.min.js"></script>

    <![endif]-->
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/lib/Hui-iconfont/1.0.8/iconfont.css" />

    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="__STATIC__/template/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->
    <link href="__STATIC__/template/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
    <!--css 加载 -->
    {load file='_CSS_/diyUpload.css'}
    {load file='_CSS_/webuploader.css'}

</head>
<body>
<nav class="breadcrumb">
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>

<div class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-article-add" >
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$product.title?$product.title:''}" placeholder="必填" id="title" name="title">
            </div>
            <span id="goodsName_tip"></span>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">兑换需积分：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="number" min="0" name="integral" id="integral" placeholder="必填" value="{$product.integral?$product.integral:''}" class="input-text" style="width:90%">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">市场价格：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="number" min="0" name="s_price" id="s_price" placeholder="必填" value="{$product.s_price?$product.s_price:''}" class="input-text" style="width:90%">
                元</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">商品单位：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" name="unit" id="unit" placeholder="必填" value="{$product.unit?$product.unit:''}" class="input-text">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">产品库存：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="number" name="stock" id="stock" placeholder="" value="{$product.stock?$product.stock:''}" class="input-text">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">产品简介：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea id="intro" placeholder="最多255个字"  cols="" rows="" class="textarea" >{$product.stock?$product.intro:''}</textarea>
            </div>
        </div>
        {notempty name='product'}
        <div class="row cl" id="img">
            <label class="form-label col-xs-4 col-sm-2">缩略图：</label>
            <div class="formControls col-xs-8 col-sm-9" style="min-height: 100px;margin-left: 5px">
                {foreach $product.img as $v}
                <div style="width:220px;height:120px;display: inline-block;text-align: center">
                    <img width="210" height="100px" class="picture-thumb" src="_GOODS_/{$v}">
                    <a onclick="imgDel(this,'{$v}')" class="img" data-img="{$v}" href="javascript:;">
                        删除
                    </a>
                </div>
                {/foreach}
            </div>
        </div>
        <input type="hidden" value="{$product.id}" id="id"/>
        {/notempty}

        <!--图片上传-->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">图片上传：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="weui-uploader__bd test" id="test"></div>
                <span id="filename" style="vertical-align: middle">最多上传5张图片</span>
            </div>
        </div>
        <!--图片上传-->

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">详细内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea id="editor" type="text/plain" style="width:100%;height:400px;">{$product.detail?$product.detail:''}</textarea>
            </div>
        </div>
        {notempty name='product'}
        <div class="row cl">
            <input type="hidden" value="{$product.id}" id="product_id"/>
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button onClick="goods_edit_submit();" class="btn btn-primary radius" type="button" id="submit">
                    <i class="Hui-iconfont">&#xe632;</i> 修改提交更新
                </button>
                <button  class="btn btn-default radius" type="reset">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
        {else /}
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button onClick="goods_save_submit();" class="btn btn-primary radius" type="button" >
                    <i class="Hui-iconfont">&#xe632;</i> 保存并提交审核
                </button>

                <button  class="btn btn-default radius" type="reset">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
        {/notempty}
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__STATIC__/template/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/layer/2.4/layer.js"></script>
<!--<script type="text/javascript" src="__STATIC__/template/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/static/h-ui.admin/js/H-ui.admin.js"></script>-->
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/template/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__STATIC__/template/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<!-- 加载js -->
{load file='_LIB_/jquery-2.1.4.js'}
{load file='_LIB_/fastclick.js'}
{load file='_JS_/jquery.Spinner.js'}
{load file='_JS_/jquery-weui.js'}
{load file='_LIB_/diyUpload.js'}
{load file='_LIB_/webuploader.min.js'}

<script type="text/javascript">

    var images="";
    $(function(){
        var ue  = UE.getEditor('editor');/*富文本编辑器*/
        var obj = $('.img');
        var l   = obj.length;
        // alert(l);
        if(l<5) {
            var limit = 5 - l;
            // 图片上传
            $("#test").diyUpload({
                url: "{:url('upload')}",
                fileNumLimit: limit,
                success: function (data) {
                    console.log(data);
                    images += data.image + ',';
                    $('#filename').text('上传成功！').css('color', 'green');
                },
                error: function (err) {
                    console.info(err.msg);
                    $('#filename').text(err.msg).css('color', 'red');
                }
            });
        }
    });

    /*产品-添加*/
    function goods_save_submit(){
        //alert(1);
        var title 	 = $('#title').val();//产品标题；
        var integral = $('#integral').val();
        var s_price  = $('#s_price').val();//市场价；
        var unit	 = $('#unit').val();//产品单位
        var stock	 = $('#stock').val();//产品库存
        var intro    = $('#intro').val();
        var detail 	 = UE.getEditor('editor').getContent() ;//富文本内容

        var data = {
            title:title,
            integral:integral,
            s_price:s_price,
            unit:unit,
            stock:stock,
            intro:intro,
            image:images,
            detail:detail
        }
        var url = "{:url('goods_hold')}";

        $.post(url,data,function(result){
            //  console.log(result);
            if(result.ok){
                layer.msg(result.msg,{icon:1,time:2000});
                setTimeout("window.location.replace(location.href)",1000);
            }else{
                layer.msg(result.msg,{icon:1,time:2000});
            }

        })

    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /* 图片删除 */
    function imgDel(obj,img){
        $(obj).parent().remove();
        $(obj).remove();
    }

    function goods_edit_submit(){
        var product_id 	 = $('#product_id').val();
        var title 	     = $('#title').val();//产品标题；
        var integral     = $('#integral').val();
        var s_price      = $('#s_price').val();//市场价；
        var unit	     = $('#unit').val();//产品单位
        var stock	     = $('#stock').val();//产品库存
        var intro        = $('#intro').val();
        var detail 	     = UE.getEditor('editor').getContent() ;//富文本内容

        var img    = '';
        $('.img').each(function(e){
            img += $(this).attr('data-img')+',';
        });
        var image = img+images;
        var arr = image.split(",");
        if(arr.length>5){
            layer.msg('最多可以有5张图片！',{icon:0,time:2000});
            return false;
        }

        var data = {
            product_id:product_id,
            title:title,
            integral:integral,
            s_price:s_price,
            unit:unit,
            stock:stock,
            intro:intro,
            image:image,
            detail:detail
        }

        var url = "{:url('goods_edit')}";

        $.post(url,data,function(result){
            console.log(result);
            if(result.ok){
                layer.msg(result.msg,{icon:1,time:2000});
                setTimeout(window.location.href="{:url('index')}",2000);
            }else{
                layer.msg(result.msg,{icon:1,time:2000});
            }

        })
    }


</script>
</body>
</html>